<template>
	<view class="main">
		<my-back></my-back>
		<view class="blank" style="height: 100rpx;"></view>
		<view class="wrap">
			<view class="lg">确认助记词</view>
			<view class="md">请按顺序抄写助记词，以确认您正确备份</view>
			
			<view class="queue">
				{{result}}
			</view>
			
			<view class="list">
				<view class="tag" v-for="(i,k) in list" :key="i" @click="add(i)">
					{{i}}
				</view>
				
				<view class="tag" @click="clear">
					重置
				</view>
			</view>
			
			<view class="blank" style="height: 20rpx;">
				
			</view>
			<button class="cu-btn radius block bg-blue" @click="next">
				下一步
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				queue: [],
				result: '',
				mnemonic: [],
				list: []
			}
		},
		onLoad(opt) {
			this.token = opt.token
			this.$u.get('/member/mnemonic/rand?token=' + opt.token).then(res => {
				this.mnemonic = res.data.result.rand_mnemonic
				this.clear();
			})
		},
		methods: {
			add(i) {
				this.queue.push(i)
				this.result = this.queue.join(' ')
				
				let idx = this.list.indexOf(i)
				this.list.splice(idx, 1)
			},
			clear() {
				this.queue = []
				this.result = ''
				this.list = [...this.mnemonic]
			},
			next() {
				this.$u.post('/member/mnemonic/check', {
					token: this.token,
					mnemonic: this.result
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							title: '校验成功',
							icon: 'none'
						})
						uni.reLaunch({
							url: '/pages/account/main'
						})
					} else {
						uni.showToast({
							title: '校验错误，请重试',
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.main {
		height: 100vh;
		background: url(../../static/images/login.png);
		background-size: cover;
		display: flex;
		flex-flow: column;
		
		.wrap {
			padding: 60rpx;
			color: #fff;
			line-height: 1.8;
			
			.lg {
				font-size: 40rpx;
				letter-spacing: 4rpx;
			}
			.md {
				font-size: 30rpx;
				letter-spacing: 2rpx;
			}
			
			.queue {
				margin-top: 80rpx;
				background: rgba(37,61,106,0.7);
				height: 200rpx;
				padding: 30rpx;
			}
			
			.list {
				display: flex;
				flex-flow: row wrap;
				justify-content: space-around;
				padding: 60rpx 0;
				
				.tag {
					background: rgba(37,61,106,0.3);
					width: 200rpx;
					height: 80rpx;
					margin-top: 10rpx;
					font-size: 28rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					position: relative;
				}
			}
		}
	}
</style>
